import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "../views/homeView/index.vue";
let routes;
let windowW = window.innerWidth;
function rouFn() {
  if (windowW < 1000) {
    routes = [
      {
        path: "/",
        name: "home",
        component: HomeView,
      },
    ];
    return;
  } else {
    routes = [
      {
        path: "/",
        name: "home",
        component: HomeView,
      },
      {
        path: "/about",
        name: "about",
        component: function () {
          return import("../views/aboutView/index.vue");
        },
      },
      {
        path: "/supply",
        name: "supply",
        component: function () {
          return import("../views/supplyView/index.vue");
        },
      },
      {
        path: "/numReal",
        name: "numReal",
        component: function () {
          return import("../views/numRealView/index.vue");
        },
      },
      {
        path: "/marketing",
        name: "marketing",
        component: function () {
          return import("../views/marketingView/index.vue");
        },
      },
      {
        path: "/antifake",
        name: "antifake",
        component: function () {
          return import("../views/antiFake/antiFake.vue");
        },
      },
      {
        path: "/visual",
        name: "visual",
        component: function () {
          return import("../views/visualView/index5.vue");
        },
      },
    ];
    return;
  }
}
rouFn();
const scrollBehavior = (to, from, savedPosition) => {
  if (savedPosition && to.meta.keepAlive) {
    return savedPosition;
  }
  return { left: 0, top: 0 };
};
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior,
});

router.beforeEach((to, from, next) => {
  if (windowW < 1000 && to.path != "/") {
    next("/");
    return;
  } else {
    next();
    return;
  }
});
export default router;
